<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <style>
        #div1 div{
            border: 1px solid #000;
            width: 300px;
            height: 200px;
            display: none;
        }
        #div1 button{
            width: 60px;
            height: 30px;
        }
    </style>
</head>
<body>
<div id="div1">
    <button>1</button>
    <button>2</button>
    <button>3</button>
    <div style="display: block">111111111111</div>
    <div>222222222222</div>
    <div>333333333333</div>
</div>
</body>
</html>
<script>

    //构造函数
    function Xiaoming(age,sex,boyfriend){
        this.age=age;
        this.sex=sex;
        this.boyfriend=boyfriend;
        this.boyfriendSay=function(){
            alert(this.age+this.sex+this.boyfriend)
        }
    }
    var obj=new Xiaoming("18","男","有男朋友");
    obj.boyfriendSay();
//    工厂函数
    function createCar(certificate,price,ins){
        var car=new Object();
        car.certificate=certificate;
        car.price=price;
        car.ins=ins;
        car.show=function(){
            return this.certificate+this.price+this.ins
        }
        return car;
    }
    var car1=createCar("合格证","20万","大众");
    var car2=createCar("合格证","50万","奥迪");
    alert(car1.show())
    alert(car2.show())



    window.onload = function () {
        var t1 = new Tab("#div1");
        t1.init();
    }

    function Tab(id) {
        this.oDiv = document.querySelector(id);
        this.aBtn = this.oDiv.querySelectorAll("button");
        this.aDiv = this.oDiv.querySelectorAll("div");
    }
    Tab.prototype.init = function () {
        var This = this;
        for(var i=0;i<this.aBtn.length;i++){
            this.aBtn[i].index = i;
            this.aBtn[i].onclick = function () {
                This.change(this)
            };
        }
    }

    Tab.prototype.change = function (obj) {
        for(var i=0;i<this.aBtn.length;i++){
            this.aDiv[i].style.display = "none";
        }
        this.aDiv[obj.index].style.display = "block";
    }
</script>